#include<iostream>
#include<string>
using namespace std;
const int N = 5e3 + 10;
short f[N][N];
string s;
int n;
int main()
{
	cin >> n;
	cin >> s;
	for (int i = n - 1; i >= 0; i--) {
		for (int j = i; j < n; j++) {
			if (s[i] == s[j]) {
				f[i][j] = f[i + 1][j - 1];
			}
			else {
				f[i][j] = min(f[i + 1][j], f[i][j - 1]) + 1;
			}
		}
	}
	cout << f[0][n - 1] << endl;
	return 0;
}